package licode.unisop.platform.utils;

import licode.unisop.types.AuthConst;

import javax.servlet.http.HttpServletRequest;

/**
 * 根据请求获取认证相关的参数（客户和用户请求信息）
 *
 * @author WR
 */
public class ReqAssembler {
    public static String getValue(HttpServletRequest req, String key) {
        String val = req.getHeader(key);
        if (null != val) {
            return val;
        }
        return req.getParameter(key);
    }

    public static String getAccessToken(HttpServletRequest req) {
        String token = getValue(req, AuthConst.ACCESS_TOKEN);
        if (null == token || token.isEmpty()) {
            token = getValue(req, AuthConst.MASTER_ACCESS_TOKEN);
        }
        return token;
    }

    public static String getPlatformId(HttpServletRequest req) {
        return getValue(req, AuthConst.PLATFORM_ID);
    }

    public static String getPlatformSecret(HttpServletRequest req) {
        return getValue(req, AuthConst.PLATFORM_SECRET);
    }

    public static String getRefreshToken(HttpServletRequest req) {
        return getValue(req, AuthConst.REFRESH_TOKEN);
    }
}
